﻿using LM.Negocio.Objetos;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace LM.Repositorios.Maps
{
    public class LocacaoMap : EntityTypeConfiguration<Locacao>
    {

        public LocacaoMap()
        {
            // Primary Key
            this.HasKey(t => t.Codigo);

            // Properties
            // Table & Column Mappings
            this.ToTable("LOCACOES");
            this.Property(m => m.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity).HasColumnName("Id");
            this.Property(t => t.Codigo).HasColumnName("Codigo").IsRequired();
            this.Property(t => t.NomeCliente).HasColumnName("NomeCliente");
            this.Property(t => t.Cpf).HasColumnName("Cpf");
            this.Property(t => t.DataHoraEntrada).HasColumnName("DataHoraEntrada");
            this.Property(t => t.DataHoraSaida).HasColumnName("DataHoraSaida");
            this.Property(t => t.Status).HasColumnName("Status");
            this.Property(t => t.Total).HasColumnName("Total");
            this.Property(t => t.Desconto).HasColumnName("Desconto");
            this.Property(t => t.DependenteId).HasColumnName("DependenteId");
            this.Property(t => t.VeiculoId).HasColumnName("VeiculoId");
            this.Property(t => t.ClienteId).HasColumnName("ClienteId");
            this.Property(t => t.VagaId).HasColumnName("VagaId");
            this.Property(t => t.TabelaPrecoId).HasColumnName("TabelaPrecoId");

            // Relationships
            this.HasOptional(t => t.Cliente)
                .WithMany(t => t.Locacoes)
                .HasForeignKey(d => d.ClienteId);
            this.HasOptional(t => t.Dependente)
                .WithMany(t => t.Locacoes)
                .HasForeignKey(d => d.DependenteId);
            this.HasOptional(t => t.TabelaPreco)
                .WithMany(t => t.Locacoes)
                .HasForeignKey(d => d.TabelaPrecoId);
            this.HasOptional(t => t.Vaga)
                .WithMany(t => t.Locacoes)
                .HasForeignKey(d => d.VagaId);
            this.HasOptional(t => t.Veiculo)
                .WithMany(t => t.Locacoes)
                .HasForeignKey(d => d.VeiculoId);
        }
    }
}
